//
//  HomeVC.m
//  OldHandPT
//
//  Created by ben on 2018/12/13.
//  Copyright © 2018 Shouny. All rights reserved.
//

#import "HomeVC.h"
#import "AnswerVC.h"
#import "HQDataBaseOperate.h"
#import "MZBaseWebViewController.h"

@interface HomeVC ()

@end

@implementation HomeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUI];
}

- (void)setUI{
    self.title = @"首页";
    [HQDataBaseOperate sharedDataBase];
}

// 科一
- (IBAction)keMuOneClick:(UIButton *)sender {
    //创建UIAlertController 设置标题，信息，样式
    NSString *messageStr = @"请选择驾照类型";
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:messageStr preferredStyle:UIAlertControllerStyleActionSheet];
    
    //改变message的大小和颜色
    NSMutableAttributedString *messageAtt = [[NSMutableAttributedString alloc] initWithString:messageStr];
    [messageAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, messageStr.length)];
    [messageAtt addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, messageStr.length)];
    [alertController setValue:messageAtt forKey:@"attributedMessage"];
    
    WEAKSELF
    /*
     subject   选择考试科目类型，1：科目1；4：科目4
     model     驾照类型，可选择参数为：c1,c2,a1,a2,b1,b2；当subject=4时可省略
     testType  测试类型，rand：随机测试（随机100个题目），order：顺序测试（所选科目全部题目）
     */
    //创建UIAlertAction对象，设置标题并添加到UIAlertController上
    UIAlertAction *cOneAction = [UIAlertAction actionWithTitle:@"C1题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"data" type:COne choose:ChooseRandom Ke:@"1"];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    [alertController addAction:cOneAction];
    UIAlertAction *cTwoAction = [UIAlertAction actionWithTitle:@"C2题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"data" type:CTwo choose:ChooseRandom Ke:@"1"];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    [alertController addAction:cTwoAction];
    UIAlertAction *bOneAction = [UIAlertAction actionWithTitle:@"B1题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"data" type:BOne choose:ChooseRandom Ke:@"1"];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    [alertController addAction:bOneAction];
    UIAlertAction *bTwoAction = [UIAlertAction actionWithTitle:@"B2题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"data" type:BTwo choose:ChooseRandom Ke:@"1"];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    [alertController addAction:bTwoAction];
    UIAlertAction *aOneAction = [UIAlertAction actionWithTitle:@"A1题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"data" type:AOne choose:ChooseRandom Ke:@"1"];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    [alertController addAction:aOneAction];
    UIAlertAction *aTwoAction = [UIAlertAction actionWithTitle:@"A2题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"data" type:ATwo choose:ChooseRandom Ke:@"1"];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    
    /*
     
     */
    [alertController addAction:aTwoAction];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertController addAction:cancelAction];
    
    [cancelAction setValue:[UIColor redColor] forKey:@"_titleTextColor"];
    
    //展现UIAlertController
    [self presentViewController:alertController animated:YES completion:nil];
}

// 科目一所有题目测试
- (IBAction)KeMuOneAll:(UIButton *)sender {
    //创建UIAlertController 设置标题，信息，样式
    NSString *messageStr = @"请选择驾照类型";
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:messageStr preferredStyle:UIAlertControllerStyleActionSheet];
    
    //改变message的大小和颜色
    NSMutableAttributedString *messageAtt = [[NSMutableAttributedString alloc] initWithString:messageStr];
    [messageAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, messageStr.length)];
    [messageAtt addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, messageStr.length)];
    [alertController setValue:messageAtt forKey:@"attributedMessage"];
    
    WEAKSELF
    /*
     subject   选择考试科目类型，1：科目1；4：科目4
     model     驾照类型，可选择参数为：c1,c2,a1,a2,b1,b2；当subject=4时可省略
     testType  测试类型，rand：随机测试（随机100个题目），order：顺序测试（所选科目全部题目）
     */
    //创建UIAlertAction对象，设置标题并添加到UIAlertController上
    UIAlertAction *cOneAction = [UIAlertAction actionWithTitle:@"C1题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"data" type:COne choose:ChooseAll Ke:@"1"];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    [alertController addAction:cOneAction];
    UIAlertAction *cTwoAction = [UIAlertAction actionWithTitle:@"C2题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"data" type:CTwo choose:ChooseAll Ke:@"1"];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    [alertController addAction:cTwoAction];
    UIAlertAction *bOneAction = [UIAlertAction actionWithTitle:@"B1题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"data" type:BOne choose:ChooseAll Ke:@"1"];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    [alertController addAction:bOneAction];
    UIAlertAction *bTwoAction = [UIAlertAction actionWithTitle:@"B2题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"data" type:BTwo choose:ChooseAll Ke:@"1"];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    [alertController addAction:bTwoAction];
    UIAlertAction *aOneAction = [UIAlertAction actionWithTitle:@"A1题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"data" type:AOne choose:ChooseAll Ke:@"1"];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    [alertController addAction:aOneAction];
    UIAlertAction *aTwoAction = [UIAlertAction actionWithTitle:@"A2题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"data" type:ATwo choose:ChooseAll Ke:@"1"];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    [alertController addAction:aTwoAction];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertController addAction:cancelAction];
    
    [cancelAction setValue:[UIColor redColor] forKey:@"_titleTextColor"];

    //展现UIAlertController
    [self presentViewController:alertController animated:YES completion:nil];
    
//    MZBaseWebViewController *vc = [[MZBaseWebViewController alloc] initWithUrlString:@"https://www.baidu.com"];
//    [self.navigationController pushViewController:vc animated:YES];
}

// 错误题库
- (IBAction)errorClick:(UIButton *)sender {
    //创建UIAlertController 设置标题，信息，样式
    NSString *messageStr = @"请选择驾照类型";
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:messageStr preferredStyle:UIAlertControllerStyleActionSheet];
    
    //改变message的大小和颜色
    NSMutableAttributedString *messageAtt = [[NSMutableAttributedString alloc] initWithString:messageStr];
    [messageAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, messageStr.length)];
    [messageAtt addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, messageStr.length)];
    [alertController setValue:messageAtt forKey:@"attributedMessage"];
    
    WEAKSELF
    /*
     subject   选择考试科目类型，1：科目1；4：科目4
     model     驾照类型，可选择参数为：c1,c2,a1,a2,b1,b2；当subject=4时可省略
     testType  测试类型，rand：随机测试（随机100个题目），order：顺序测试（所选科目全部题目）
     */
    //创建UIAlertAction对象，设置标题并添加到UIAlertController上
    UIAlertAction *cOneAction = [UIAlertAction actionWithTitle:@"C1题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSArray *arr = [HQDataBaseOperate queryAllCOneMessage];
        if (arr.count > 0) {
            AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"base" type:COne choose:ChooseAll Ke:@"1"];
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }else{
            TKAertCenterManager(@"C1暂无答错题")
        }
    }];
    [alertController addAction:cOneAction];
    UIAlertAction *cTwoAction = [UIAlertAction actionWithTitle:@"C2题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSArray *arr = [HQDataBaseOperate queryAllCTwoMessage];
        if (arr.count > 0) {
            AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"base" type:CTwo choose:ChooseAll Ke:@"1"];
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }else{
            TKAertCenterManager(@"C2暂无答错题")
        }
    }];
    [alertController addAction:cTwoAction];
    UIAlertAction *bOneAction = [UIAlertAction actionWithTitle:@"B1题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSArray *arr = [HQDataBaseOperate queryAllBOneMessage];
        if (arr.count > 0) {
            AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"base" type:BOne choose:ChooseAll Ke:@"1"];
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }else{
            TKAertCenterManager(@"B1暂无答错题")
        }
    }];
    [alertController addAction:bOneAction];
    UIAlertAction *bTwoAction = [UIAlertAction actionWithTitle:@"B2题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSArray *arr = [HQDataBaseOperate queryAllBTwoMessage];
        if (arr.count > 0) {
            AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"base" type:BTwo choose:ChooseAll Ke:@"1"];
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }else{
            TKAertCenterManager(@"B2暂无答错题")
        }
    }];
    [alertController addAction:bTwoAction];
    UIAlertAction *aOneAction = [UIAlertAction actionWithTitle:@"A1题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSArray *arr = [HQDataBaseOperate queryAllAOneMessage];
        if (arr.count > 0) {
            AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"base" type:AOne choose:ChooseAll Ke:@"1"];
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }else{
            TKAertCenterManager(@"A1暂无答错题")
        }
    }];
    [alertController addAction:aOneAction];
    UIAlertAction *aTwoAction = [UIAlertAction actionWithTitle:@"A2题库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSArray *arr = [HQDataBaseOperate queryAllATwoMessage];
        if (arr.count > 0) {
            AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"base" type:ATwo choose:ChooseAll Ke:@"1"];
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }else{
            TKAertCenterManager(@"A2暂无答错题")
        }
    }];
    
    /*
     
     */
    [alertController addAction:aTwoAction];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertController addAction:cancelAction];
    
    [cancelAction setValue:[UIColor redColor] forKey:@"_titleTextColor"];
    
    //展现UIAlertController
    [self presentViewController:alertController animated:YES completion:nil];
}



// 科四
- (IBAction)keMuFourClick:(UIButton *)sender {
    AnswerVC *vc = [[AnswerVC alloc] initWithUrl:@"data" type:COne choose:ChooseAll Ke:@"4"];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)setData{
    /*
     subject   选择考试科目类型，1：科目1；4：科目4
     model     驾照类型，可选择参数为：c1,c2,a1,a2,b1,b2；当subject=4时可省略
     testType  测试类型，rand：随机测试（随机100个题目），order：顺序测试（所选科目全部题目）
     */
    NSString *URL = [NSString stringWithFormat:@"http://v.hqew.cn/jztk/query?subject=1&model=c1&key=94da3332e693e9256d292422509f316e&testType=rand"];
    [LCNetworking getWithURL:URL Params:nil success:^(id responseObject) {
        NSLog(@"GET_success____%@", responseObject);
        
    } failure:^(NSString *error) {
        NSLog(@"GET_failure____%@", error);
    }];
}

@end
